﻿using System;
using System.Data;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BaseData;
using BaseData.UI;
using TaxBiz.SysConfig;
using TaxEntity.SysConfig;


namespace Admin.SysConfig
{
    public partial class DiduanModify : BaseCommon.BasePage
    {
        protected string id = string.Empty;
        protected DiDuanEntity de = new DiDuanEntity();
        protected DiDuanBiz db = new DiDuanBiz();
        protected DataTable dtXiangzhen = null;
        protected DataTable dtJiedao = null;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!HasPower())
            {
                Jscript.AlertAndGoBack("您权限不足，不能操作");
                return;
            }
            id = PageContext.GetRequest("id");
            if (string.IsNullOrEmpty(id))
            {
                Jscript.AlertAndGoBack("参数错误");
                return;
            }
            int iId = 0;
            int.TryParse(id, out iId);
            if (iId <= 0)
            {
                Jscript.AlertAndGoBack("参数错误");
                return;
            }
            de = db.GetEntityById(iId);
            if (de == null)
            {
                Jscript.AlertAndGoBack("参数错误");
                return;
            }

            //dtXiangzhen = new XiangzhenBiz().GetList();
            //if (de.XiangzhenID.HasValue && de.XiangzhenID.Value > 0)
            //{
            //    dtJiedao = new JiedaoBiz().GetList(de.XiangzhenID.Value);
            //}
            string action = PageContext.GetRequest("action");
            if (!string.IsNullOrEmpty(action))
            {
                this.DoAction(action, iId);
            }
        }

        protected bool DoAction(string action, int id)
        {
            DiDuanEntity de = new DiDuanEntity();
            de.ID = id;
            de.OptUserID = UserLogin.UserId;
            de.Code = PageContext.GetRequest("txtCode");
            de.Name = PageContext.GetRequest("txtName");
            //乡镇
            string strXiangzhen = PageContext.GetRequest("selXiangzhen");
            int xiangzhenID = 0;
            int.TryParse(strXiangzhen, out xiangzhenID);
            de.XiangzhenID = xiangzhenID;
            //街道
            string strJiedao = PageContext.GetRequest("selJiedao");
            int JiedaoID = 0;
            int.TryParse(strJiedao, out JiedaoID);
            de.JiedaoID = JiedaoID;
            //其它
            string strPerTax = PageContext.GetRequest("txtPerTax");
            decimal perTax = 0;
            decimal.TryParse(strPerTax, out perTax);
            if (perTax > 0)
            {
                de.PerTax = perTax;
            }
            string strMinPrice = PageContext.GetRequest("txtMinPrice");
            decimal minPrice = 0;
            decimal.TryParse(strMinPrice, out minPrice);
            if (minPrice > 0)
            {
                de.MinPrice = minPrice;
            }
            bool isSucc = db.Update(de, UserLogin);
            if (!isSucc)
            {
                Jscript.Alert("修改失败");
                return false;
            }

            Jscript.AlertAndRedirect("修改成功", "DiduanModify.aspx?id="+id);
            return true;
        }
    }
}